<script>
import global from "@/views/global/global";
import axios from "axios";

export default {
  name: "BusinessCard",
  data() {
    return {
      realName:global.user.realName,
      business:{
        applicantName:global.user.realName,
        applicationTime:new Date(),
        applicantDepartment:global.user.departmentName,
        applicantPosition:global.user.title,
        phoneNumber:'',
        quantity:'',
        remarks:'',
      }
    }
  },
  methods: {
    getData() {
      if(this.business.phoneNumber === null || this.business.phoneNumber === undefined || this.business.phoneNumber === ''){
        this.$message({
          type: 'warning',
          message: '请输入手机号!'
        });
        return;
      }
      if(this.business.phoneNumber.length > 11 || this.business.phoneNumber.length < 11){
        this.$message({
          type: 'warning',
          message: '手机号必须是11位!'
        });
        return;
      }
      if(this.business.quantity === null || this.business.quantity === ''){
        this.$message({
          type: 'warning',
          message: '请输入数量!'
        });
        return;
      }
      if(this.business.remarks === null || this.business.remarks === ''){
        this.$message({
          type: 'warning',
          message: '请输入备注!'
        });
        return;
      }
      this.$confirm('确定提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

      axios.post("/oa/business/addition", this.business).then((res) => {
        console.log(res.data.result)
        if (res.data.result === "true") {
          this.$message({
            type: 'success',
            message: '申请成功!'
          });
          this.$router.push('/HomePageView')
        } else {
          this.$message({
            type: 'error',
            message: '申请失败!'
          });
        }
      })
    }).catch(
          () => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          }
      )
    },
    cancel() {
      // 返回到我的桌面
      this.$router.push('/HomePageView')
    }
    }
}
</script>

<template>
  <div class="titleBox">
    名片印制流程
  </div>

  <el-form
      label-width="auto"
      :model="book"
      style="max-width: 600px"
  >
    <el-form-item label="申请人" >
      <span>{{business.applicantName}}</span>
    </el-form-item>

    <el-form-item label="申请时间" >
      <el-date-picker disabled
                      v-model="business.applicationTime"
                      type="datetime"
      />
    </el-form-item>

    <el-form-item label="部门">
      <span>{{business.applicantDepartment}}</span>
    </el-form-item>

    <el-form-item label="职业">
      <span>{{business.applicantPosition}}</span>
    </el-form-item>

    <el-form-item label="手机号">
      <el-input v-model="business.phoneNumber" placeholder="请输入手机号" />
    </el-form-item>

    <el-form-item label="数量">
      <el-input v-model="business.quantity" placeholder="请输入数量"/>
    </el-form-item>

    <el-form-item label="备注">
      <el-input v-model="business.remarks" placeholder="请输入备注"/>
    </el-form-item>

    <el-form-item label="下一步审批人">
      <el-select v-model="business.applicantName" placeholder="审批人" style="width: 240px">
        <!--        默认选中当前用户-->
        <el-option
            :key="this.realName"
            :label="this.realName"
            :value="this.realName"
        />
      </el-select>
    </el-form-item>
    <el-button type="primary" @click="getData()">提交</el-button>
    <el-button @click="cancel">取消</el-button>
  </el-form>
</template>

<style scoped lang="less">


</style>
